import { v2 } from 'cc';
import { _decorator, Component, Node, v3, Tween, tween } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('fingerClickAnim')
export class fingerClickAnim extends Component {
    @property
    animTime = 0.15;
    @property
    offset = v2(10, 30);

    onEnable() {
        this.showAnim();
    }
    onDisable(): void {
        Tween.stopAllByTarget(this.pos);
    }

    pos = v3();
    showAnim() {
        Tween.stopAllByTarget(this.pos);
        this.pos.set(0, 0, 0);
        this.node.setPosition(this.pos);
        let t = this.animTime;

        // 从上往下点击
        tween(this.pos).repeatForever(
            tween(this.pos).
                to(t * 3, { x: this.offset.x, y: this.offset.y }, { easing: 'sineInOut' }).
                to(t, { x: 0, y: 0 }, { easing: 'sineOut' }).
                start()
        ).start();
    }

    update(dt) {
        this.node.setPosition(this.pos);
    }
}

